home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr30 / hercb21.zip / TESTPIX.C < prev    next >
Text File  |  1993-05-03  |  5KB  |  232 lines

  1. /**********************************************************************
  2.  *
  3.  *    TEST / DEMO PROGRAM FOR HERCBIOS
  4.  *        Dave Tutelman  -  August 1988
  5.  *
  6.  *    This program has the purposes of:
  7.  *       -    Testing HERCBIOS on your machine.
  8.  *       -    Demonstrating how to program using HERCBIOS.
  9.  *    It uses a "library" of utility routines in HERCPIXL.C.
  10.  *
  11.  *    TESTPIX.C is written in pretty standard C, so it should be
  12.  *    independent of which brand of C compiler you use
  13.  *    (though I've only tested it with Borland's Turbo C).
  14.  */
  15.  
  16. #include    <stdio.h>
  17.  
  18. #define    HERC29    8    /* 29 x 90 Hercules mode */
  19. #define    HERC43    9    /* 43 x 90 Hercules mode */
  20.  
  21. #define    NORM    0x07    /* normal video */
  22. #define    UNDER    0x01    /* underscore */
  23. #define    REVERSE    0x70    /* reverse video */
  24. #define    INVIS    0x00    /* invisible */
  25.  
  26. /* set up a graphic character table for hyper-ASCII */
  27. char graf_tbl [5][8] =
  28.         { { 0x00, 0x38, 0x7C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38 },
  29.           { 0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x44, 0x38 },
  30.           { 0xFF, 0xC7, 0x83, 0x01, 0x01, 0x01, 0x83, 0xC7 },
  31.           { 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF },
  32.           { 0x03, 0x07, 0x0E, 0x1C, 0x38, 0x70, 0xE0, 0xC0 } };
  33.  
  34. main (argc,argv)
  35.   int    argc;
  36.   char    *argv[];
  37. {
  38.     unsigned int i,j;
  39.     unsigned int f,g;
  40.     int mode;
  41.     int ht,wid;
  42.     int rows;
  43.  
  44.     /* check mode argument */
  45.     if (argc != 2)
  46.         quitmsg();
  47.     mode = atoi (argv[1]);        /* i = video mode */
  48.     switch (mode) {
  49.       case 4:            /* 320 x 200 CGA */
  50.       case 5:
  51.         ht = 200;
  52.         wid = 320;
  53.         f=20; g=32;
  54.         rows = 25;
  55.         break;
  56.  
  57.       case 6:            /* 640 x 200 CGA */
  58.         ht = 200;
  59.         wid = 640;
  60.         f=20;g=64;
  61.         rows = 25;
  62.         break;
  63.  
  64.       case HERC29:
  65.         ht = 348;
  66.         wid = 720;
  67.         f=35;g=72;
  68.         rows = 29;
  69.         break;
  70.  
  71.       case HERC43:
  72.         ht = 348;
  73.         wid = 720;
  74.         f=35;g=72;
  75.         rows = 43;
  76.         break;
  77.  
  78.       default:
  79.         quitmsg ();
  80.         break;
  81.     }
  82.  
  83.     /* set up the int 1F vector to point to bullseye */
  84.     poke (0, 4*0x1F, graf_tbl);
  85.     poke (0, 4*0x1F +2, _DS);
  86.  
  87.     grafix (mode);
  88.  
  89.     /* now draw a couple of lines */
  90.     for (i=0; i<wid; i++)
  91.     {
  92.         j = (i * f) / g;
  93.         if (j >= ht) break;
  94.         pixel (i, j, 1);
  95.         pixel (i, ht - j, 1);
  96.     }
  97.  
  98.     j=getchar();        /* wait for CR */
  99.  
  100.     /* a different pattern on page 1 */
  101.     if (mode > 6)        /* can't do it for emulated CGA */
  102.         swpage (1);
  103.     f = wid / 8;
  104.     g = ht / 6;
  105.     for (i=0; i<wid; i++)
  106.     for (j=0; j<ht; j=j+g)
  107.         pixel (i,j,1);
  108.     for (i=0; i<wid; i=i+f)
  109.     for (j=0; j<ht; j++)
  110.         pixel (i,j,1);
  111.  
  112.     if (mode > 6) {
  113.         /* switch back and forth a couple of times */
  114.         j=getchar();
  115.         swpage (0);
  116.         j=getchar();
  117.         swpage (1);
  118.     }
  119.  
  120.     /* add some writing */
  121.     j=getchar();
  122.     setattr (NORM);
  123.     dline (10, 2, "Hello, there!");
  124.     dline (10, 3, "Second LINE of text.");
  125.     dline (10, 4, "All on display page 1.");
  126.  
  127.     j=getchar();
  128.     charset();
  129.  
  130.     if (mode > 6) {
  131.         /* repeat for page 0 */
  132.         j=getchar();
  133.         swpage (0);
  134.  
  135.         /* add some writing */
  136.         dline (10, 2, "Hello, there!");
  137.         dline (10, 3, "Second LINE of text.");
  138.         dline (10, 4, "this time on display page 0.");
  139.     }
  140.  
  141.     /* Check two "obscure" features:
  142.      *   multiple character write & custom character table.
  143.      */
  144.     j = getchar();
  145.     setattr (UNDER);
  146.     for (j=0; j<5; j++)
  147.         nchar (44, 14+j, 0x80+j, 16);
  148.     setattr (REVERSE);
  149.     for (j=0; j<5; j++)
  150.         nchar (44, 19+j, 0x80+j, 16);
  151.  
  152.     /* Create a scroll area, and scroll it a couple of times */
  153.     j=getchar();
  154.     if ((mode==HERC29) || (mode==HERC43))
  155.         setattr (REVERSE);
  156.     else    setattr (NORM);
  157.     for (i=0; i<16; i++)
  158.         for (j=0; j<32; j++)
  159.             dchar (j+4, i+6, (char) i + 'A');
  160.     j=getchar();
  161.     scroll (7,5, 20,34, 1,NORM);
  162.  
  163.     j=getchar();
  164.     scroll (7,5, 20,34, 1,NORM);
  165.     
  166.     j=getchar();
  167.     scroll (7,5, 20,34, -1,REVERSE);
  168.  
  169.     j=getchar();
  170.     scroll (7,5, 20,34, -1,REVERSE);
  171.  
  172.     /* And a blanked-out "scroll area" */
  173.     j=getchar();
  174.     scroll (9,9, 18,30, 0, NORM);
  175.  
  176.     /* Test TTY write and "automatic" full-screen scroll */
  177.     j = getchar();
  178.     dchar (0,rows-6, 2);
  179.     for (i=0; i<6; i++) {
  180.         for (j=0; j<100; j++)
  181.             hputc ((char)i + 'A');
  182.         hputc ('\n');
  183.     }
  184.  
  185.     /* back to alpha mode */
  186.     j = getchar();
  187.     alfa();
  188. }
  189.  
  190. /**********************************************************************/
  191.  
  192. charset ()        /* show the whole character set in all colors */
  193. {
  194.     setattr (NORM);        charset_1 (6,4);
  195.     setattr (UNDER);    charset_1 (10,4);
  196.     setattr (INVIS);    charset_1 (14,4);
  197.     setattr (REVERSE);    charset_1 (18,4);
  198.     setattr (NORM);
  199. }
  200.  
  201. charset_1 (y,x)        /* show the whole character set in one color */
  202.   int    y,x;
  203. {
  204.     int    i,j;
  205.  
  206.     for (i=0; i<4; i++)
  207.         for (j=0; j<32; j++)
  208.             dchar (j+x, i+y, (char) (32*i+j));
  209. }
  210.  
  211. dline (x, y, chstr)    /* write character-string at x,y */
  212.     int     x,y;
  213.     char    chstr [90];
  214. {
  215.     int    i;
  216.     char    *p;
  217.  
  218.     i=0;
  219.     for ( p=chstr; *p != '\0'; p++ )
  220.     {
  221.         dchar ( x+i, y, *p );
  222.         i++;
  223.     }
  224. }
  225.  
  226. /***************************************************************/
  227.  
  228. quitmsg()
  229. {
  230.     puts("usage: testpix <valid graphics mode>\n");
  231.     exit (-1);
  232. }